class Solution {
public:
    vector<vector<int>> ret;
    vector<int> path;
    int target;
    vector<vector<int>> combinationSum(vector<int>& candidates, int _target) {
        target = _target;
        dfs(candidates, 0, 0);
        return ret;
    }
    void dfs(vector<int>& candidates, int sum, int index) {
        if (sum > target) {
            return;
        } else if (sum == target) {
            ret.push_back(path);
        }
        for (int i = index; i < candidates.size(); i++) {
            sum += candidates[i];
            path.push_back(candidates[i]);
            dfs(candidates, sum, i);
            path.pop_back();
            sum -= candidates[i];
        }
    }
};